/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.notaria.guerrasalas.bc;

import com.notaria.guerrasalas.be.Vehiculo;
import gob.satt.comun.jpa.Command;
import java.util.List;
import javax.persistence.EntityManager;
import oracle.toplink.essentials.config.HintValues;
import oracle.toplink.essentials.config.TopLinkQueryHints;

/**
 *
 * @author Administrator
 */
public class FiltrarVehiculosCommand implements Command<List<Vehiculo>> {

    private String criterio;

    public FiltrarVehiculosCommand(String criterio) {
        this.criterio = criterio;
    }

    @Override
    public List<Vehiculo> execute(EntityManager em) throws Exception {
        List<Vehiculo> vehiculos = null;
        if (criterio != null && !criterio.trim().equals("")) {
            vehiculos = (List<Vehiculo>) em.createNamedQuery("Vehiculo.findByNroPlacaODua")
                    .setParameter("nroPlaca", criterio.toUpperCase() + "%")
                    .setParameter("dua", criterio.toUpperCase() + "%")
                    .setHint(TopLinkQueryHints.REFRESH, HintValues.TRUE)
                    .getResultList();
        }
        return vehiculos;
    }
}
